<template>
    <div class="database-info">
        <el-tabs type="border-card">
            <el-tab-pane :label="$t('menu.system.timer')">
                <all-sort-and-search-table
                        showSelect
                        showOperate
                        :columns="tableColumns"
                        @getData="getTableList"
                        @custom-click="customClicker"
                >
                    <template slot="form" slot-scope="{ data }">
                        <el-button
                                type="primary"
                                :disabled="data == null || data.length === 0"
                                @click="() => 1"
                        >{{$t('quartz.add')}}</el-button>
                    </template>
                </all-sort-and-search-table>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>

<script>
    import timer from "@/serveapi/timer.js";
    import AllSortAndSearchTable from "@/components/Table/AllSortAndSearchTable.vue";
    export default {
        components: {
            AllSortAndSearchTable,
        },
        data() {
            return {
                tableColumns:[
                    {
                        key:'id',
                        label:'ID',
                        labelEn:'ID',
                        width:230,
                        disabled:true
                    },
                    {
                        key:'jobName',
                        label:'任务名',
                        labelEn:'jobName',
                    },
                    {
                      key:'jobClass',
                      label:'任务执行器',
                      labelEn:'jobClass'
                    },
                    {
                        key:'status',
                        label:'执行状态',
                        labelEn:'status',
                        enSelectAble:true,
                        selectList:['执行中','暂停']
                    },
                    {
                        key:'evictionIntervalTimerInMs',
                        label:'执行间隔',
                        labelEn:'evictionIntervalTimerInMs'
                    },
                    {
                        key: "operate",
                        label: "操作",
                        labelEn:'operate',
                        disabled:true,
                        options:[
                            {key:'start',label:'开始',type:'success'},
                            {key:'pause',label:'中止',type:'warning'}
                        ]
                    }
                ]
            }
        },
        methods:{
            async getTableList(setData,search){
                let g=this;
                let data=await timer.listAll();
                data=data.map(d=>{
                    g.$set(d,'status',d.status===1?'执行中':'已暂停');
                    return d;
                });
                setData(data);
                search();
            }  ,
            customClicker(index,row,key){
                if (key==='pause'){
                    timer.pause(row.jobName).then(res=>{
                        console.log(res)
                    })
                }else{
                    timer.resume(row.jobName).then(res=>{

                    })
                }
            }
        },

        mounted() {
           console.log(this.$store.getters.GET_AUTH)
        }
    };
</script>

<style lang="scss" scoped>
    .database-info {
        margin: 30px;
    }
</style>
